import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;

public class Setup {
	static User[] USERA = new User[1000990];
	static User[] USERB = new User[1000990];
	static Item[] ITEMA = new Item[624961];
	static Item[] ITEMB = new Item[624961];

	static String PATH_USER_A = "../track1/trainIdx1.txt" + ".serA";
	static String PATH_ITEM_A = "../track1/trainIdx1.txt" + ".serA.item";
	static String PATH_USER_B = "../track1/validationIdx1.txt" + ".ser";
	static String PATH_ITEM_B = "../track1/validationIdx1.txt" + ".ser.item";

	public static void main(String[] args) {
		setup();
	}

	static void setup() {
		long time;

		time = System.currentTimeMillis();
		readSerializedUA();
		readSerializedUB();
		System.out.println(System.currentTimeMillis() - time);

		time = System.currentTimeMillis();
		readSerializedIA();
		readSerializedIB();
		System.out.println(System.currentTimeMillis() - time);
	}

	static void readSerializedUA() {
		System.out.println("readSerializedUA: " + PATH_USER_A);

		try {
			InputStream file = new FileInputStream(PATH_USER_A);
			InputStream buffer = new BufferedInputStream(file);
			ObjectInput input = new ObjectInputStream(buffer);
			try {
				USERA = (User[]) input.readObject();
			} finally {
				input.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	static void readSerializedUB() {
		System.out.println("readSerializedUB: " + PATH_USER_B);

		try {
			InputStream file = new FileInputStream(PATH_USER_B);
			InputStream buffer = new BufferedInputStream(file);
			ObjectInput input = new ObjectInputStream(buffer);
			try {
				USERB = (User[]) input.readObject();
			} finally {
				input.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	static void readSerializedIA() {
		System.out.println("readSerializedIA: " + PATH_ITEM_A);

		try {
			InputStream file = new FileInputStream(PATH_ITEM_A);
			InputStream buffer = new BufferedInputStream(file);
			ObjectInput input = new ObjectInputStream(buffer);
			try {
				ITEMA = (Item[]) input.readObject();
			} finally {
				input.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	static void readSerializedIB() {
		System.out.println("readSerializedIB: " + PATH_ITEM_B);

		try {
			InputStream file = new FileInputStream(PATH_ITEM_B);
			InputStream buffer = new BufferedInputStream(file);
			ObjectInput input = new ObjectInputStream(buffer);
			try {
				ITEMB = (Item[]) input.readObject();
			} finally {
				input.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
